const router = require('koa-router')()
const { Register } = require('../model/index')
const jwt = require('jsonwebtoken')

router.get('/home', async (ctx, next) => {
    const token = ctx.header.authorization.slice(7)
    const resToken = jwt.verify(token, 'test and verify')
    if (resToken) {
        const res = await Register.findOne({
            where: {
                email: resToken.email,
                password: resToken.password
            }
        });
        if (res) {
            // 才会执行你想操作数据
            const homeRes = await Register.findAll()
            ctx.body = {
                code:200,
                message: '操作成功,进入首页',
                homeRes

            }
        } else {
            ctx.body = {
                code: 600,
                message: '该账户还未注册，请先注册账户',
            }
        }
    } else {
        ctx.body = {
            code: 302,
            message: '未登录或者登录超时'
        }
    }
})



module.exports = router